#include <stdio.h>
#include "main.h"
#include "mem.h"
#include "uart.h"
#include "funcBlock.h"
#include "funcBlock_OR.h"

struct fb_OR_2
{
	uint8_t type;
	function_t func;
	uint8_t in0;
	uint8_t in1;
	uint8_t out0;
};

struct fb_OR_4
{
	uint8_t type;
	function_t func;
	uint8_t in0;
	uint8_t in1;
	uint8_t in2;
	uint8_t in3;
	uint8_t out0;
};

// ****************** FunctionBlock AND 2xIn 1xOut *******************
void function_fb_OR_2(struct funcBlock_t *_fb)
{
	struct fb_OR_2 *fb = (struct fb_OR_2*)_fb;

	setState(fb->out0, (getState(fb->in0) | getState(fb->in1)));
}

struct funcBlock_t* get_fb_OR_2(uint8_t in0, uint8_t in1, uint8_t out0)
{
	struct fb_OR_2 *fb = NULL;

	fb = (struct fb_OR_2*)getMem(sizeof(struct fb_OR_2));
	if (fb != NULL)
	{
		//uart_puts("OR_2\n");
		fb->type = FB_TYPE_OR2;
		fb->func = function_fb_OR_2;
		fb->in0 = in0;
		fb->in1 = in1;
		fb->out0 = out0;
	}
	return (struct funcBlock_t*)fb;
}

// ****************** FunctionBlock AND 4xIn 1xOut *******************

void function_fb_OR_4(struct funcBlock_t *_fb)
{
	struct fb_OR_4 *fb = (struct fb_OR_4*)_fb;

	setState(fb->out0, (getState(fb->in0) | getState(fb->in1) | getState(fb->in2) | getState(fb->in3)));
}

struct funcBlock_t* get_fb_OR_4(uint8_t in0, uint8_t in1, uint8_t in2, uint8_t in3, uint8_t out0)
{
	struct fb_OR_4 *fb = NULL;

	fb = (struct fb_OR_4*)getMem(sizeof(struct fb_OR_4));
	if (fb != NULL)
	{
		//uart_puts("OR_4\n");
		fb->type = FB_TYPE_OR4;
		fb->func = function_fb_OR_4;
		fb->in0 = in0;
		fb->in1 = in1;
		fb->in2 = in2;
		fb->in3 = in3;
		fb->out0 = out0;
	}

	return (struct funcBlock_t*)fb;
}

struct funcBlock_t* get_fb_OR_8(uint8_t in_8, uint8_t out0)
{
#ifdef __AVR__
	#warning "xxxx"
#endif
return NULL;
}
